<?php
declare (strict_types = 1);

namespace app\command;

use app\admin\model\Channel;
use app\admin\model\Other;
use app\admin\model\Project;
use app\admin\model\project\Income;
use app\admin\model\Taobao;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Data extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('Data');
        // 设置参数
        $this->setDescription('素材同步')->setHelp("php think Data");
    }

    protected function execute(Input $input, Output $output)
    {

        $channel = (new Income())->select()->toArray();
        foreach ($channel as $val){
            $money = (float)$val['money'];
            (new Income())->where(['id' => $val['id']])->update(['income' => $money]);
            echo $val['id']."\n";
        }


        die;


        $channel = (new Taobao())->select()->toArray();
        foreach ($channel as $val){
            $date = strtotime((string)$val['date']);
            (new Taobao())->where(['id' => $val['id']])->update(['date' => $date]);
            echo $val['id']."\n";
        }


        die;


        $channel = (new Channel())->select()->toArray();
        foreach ($channel as $val){
            $date = strtotime((string)$val['date']);
            (new Channel())->where(['id' => $val['id']])->update(['date' => $date]);
            echo $val['id']."\n";
        }


        die;



        $project = (new Project())->select();
        foreach ($project as $val){
           $income = json_decode($val['income'], true);
           foreach ($income as $item){
               $data['project_id'] = $val['id'];
               $data['date'] = strtotime($item['time']);
               $data['income_type'] = $val['type'];
               $data['money'] = $item['amount'];
               if($item['type'] == '首款'){
                   $data['type'] = 1;
               }elseif ($item['type'] == '中款'){
                   $data['type'] = 2;
               }elseif ($item['type'] == '尾款'){
                   $data['type'] = 3;
               }else{
                   $data['type'] = 4;
               }
               $data['create_time'] = strtotime($item['time']);
               $data['update_time'] = strtotime($item['time']);
               (new Income())->insert($data);
               echo $val['id']."\n";
           }
        }
    }
}
